package com.cmnit.tools

import com.cmnit.tools.kafka.KafkaTools
import com.cmnit.tools.utils.ConfigurationManager
import org.apache.hadoop.security.UserGroupInformation
import org.apache.log4j.Logger

object App {
  val logger: Logger = Logger.getLogger(App.getClass)

  def main(args: Array[String]): Unit = {
    // 获取程序类型（test/product）
    val appType = args(0)
    ConfigurationManager.setResources(appType)

    // kerberos配置
    System.setProperty("java.security.auth.login.config", ConfigurationManager.getProperty("java.security.auth.login.config"))
    System.setProperty("java.security.krb5.conf", ConfigurationManager.getProperty("java.security.krb5.conf"))
    System.setProperty("zookeeper.sasl.clientconfig", "Client")
    System.setProperty("zookeeper.sasl.client", "true")

    // TODO 本地模式需要用户密码传入
    UserGroupInformation.loginUserFromKeytab(ConfigurationManager.getProperty("kerberos.principal"), ConfigurationManager.getProperty("keytab.file"))
    logger.info("login user: " + UserGroupInformation.getLoginUser)

    val appName = args(1)

    logger.info("appName:" + appName)
    appName match {
      // 测试
      case "kafka" => KafkaTools.getOffset(args(2), args(3))

      case _ => {
        System.exit(1)
      }
    }
  }
}
